package com.ygqh.baby.service;

import com.ygqh.baby.ao.Message;
import com.ygqh.baby.ao.QueryInfo;
import com.ygqh.baby.ao.ResultSet;
import com.ygqh.baby.ao.SalesPlatform;
import com.ygqh.baby.model.*;
import com.ygqh.baby.po.YgOrder;
import com.ygqh.baby.po.YgPrepayBookRecord;
import com.ygqh.baby.po.YgProductBook;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

public interface YgPrepayBookRecordService {

    List<YgPrepayBookRecord> find();

    int findCount();

    YgPrepayBookRecord findById(Long id);

    int deleteSoft(Long[] ids);

    int deleteSoft(Long id);

    int save(YgPrepayBookRecord ygPrepayBookRecord);

    int update(YgPrepayBookRecord ygPrepayBookRecord);

    int saveOrUpdate(YgPrepayBookRecord ygPrepayBookRecord);

    ResultSet<ProductBookRecordModel> search(QueryInfo queryInfo, String q, Long userId, YgPrepayBookRecord.RecordStatus recordStatus, String userName);

    /**
     * @param recordCode 记录编号
     * @return
     */
    ProductBookRecordModel findByRecordCode(Long recordCode);

    List<ProductBookRecordModel> findByRecordCode(List<Long> recordCodeList);

    /**
     * 提交定金预售记录
     *
     * @param userId
     * @param carModel
     * @param productBook
     * @return
     */
    Message commitRecord(Long userId, YgShoppingCarModel carModel, YgProductBook productBook);

    /**
     * 获取定金结算的各项金额
     *
     * @param carModel
     * @param productBook
     * @return
     */
    Map<String, Object> getProductBookPrice(YgShoppingCarModel carModel, YgProductBook productBook);

    /**
     * 提交订单（定金记录生成订单）
     *
     * @param userId
     * @param recordList
     * @param requestParam
     * @param salesPlatform
     * @return
     */
    Message commitOrder(Long userId, String userName, List<ProductBookRecordModel> recordList, CommitOrderRequestParam requestParam, SalesPlatform salesPlatform);

    /**
     * 分页获取记录
     *
     * @param queryInfo
     * @param q            记录编号
     * @param userId
     * @param recordStatus
     * @return
     */
    List<ProductBookRecordModel> findList(QueryInfo queryInfo, String q, Long userId, YgPrepayBookRecord.RecordStatus recordStatus);

    /**
     * 验证商品信息
     *
     * @param userId
     * @param skuInfo
     * @return
     */
    Message validateProductWithProductBook(Long userId, BaseSkuInfo skuInfo);

    /**
     * 处理记录集中的商品信息
     *
     * @param recordList
     * @param userId
     * @param giftSkuId  赠品sku
     * @return
     */
    Message processItemInfoWithRecordList(List<ProductBookRecordModel> recordList, Long userId, Long giftSkuId);

    /**
     * 验证活动订单号
     *
     * @param recordCode 支持多条记录
     * @return
     */
    Message validateRecordCode(String recordCode);

    /**
     * @param orderId      关联订单编号
     * @param recordStatus
     * @return
     */
    List<ProductBookRecordModel> findByOrderId(Long orderId, YgPrepayBookRecord.RecordStatus recordStatus);

    /**
     * 退定金
     *
     * @param recordCode
     * @return
     */
    Message refundRecord(Long recordCode);

    void refundRecord(Long orderId, List<ProductBookRecordModel> modelList);

    Message cancelRecord(ProductBookRecordModel recordModel);

    /**
     * 取消订单
     *
     * @param recordCode
     * @return
     */
    Message cancelRecord(Long recordCode);

    /**
     * @param startDate    开始时间（包括）
     * @param endDate      结束时间（不包括）
     * @param recordStatus 记录状态
     * @return
     */
    List<ProductBookRecordModel> findBetweenDate(Date startDate, Date endDate, YgPrepayBookRecord.RecordStatus recordStatus);

    /**
     * @param bookId       活动id
     * @param recordStatus 记录状态
     * @return
     */
    List<ProductBookRecordModel> findByBookId(Long bookId, YgPrepayBookRecord.RecordStatus recordStatus);

    /**
     * 根据退货单号退款
     *
     * @param returnCode
     * @param refundPrice
     * @return
     */
    Message refundRecordByReturnCode(String returnCode, BigDecimal refundPrice);

    /**
     * @param startDate 限制开始时间
     * @return
     */
    List<ProductBookRecordModel> findForCancel(Date startDate);

    /**
     * 过滤掉未参与退款的活动单定金
     *
     * @param order      订单信息
     * @param returnInfo 退单信息
     */
    void checkBookOrderForReturn(YgOrder order, YgReturnInfoModel returnInfo);

    void asyncUpdateRecordByCancelOrder(Long orderId);

    void asyncUpdateRecordByCancelOrder(List<Long> orderIdList);

    /**
     * 取消订单，清空待付尾款的绑定单号
     *
     * @param orderId
     * @return
     */
    int updateRecordByCancelOrder(Long orderId);

    List<Map<String, Object>> search(Long id);

    void cancelRecord(Long orderId, List<ProductBookRecordModel> modelList);

}
